//
//  AddCoverView.m
//  Shengzhuli
//
//  Created by FXGuo on 2017/5/11.
//  Copyright © 2017年 kamangkeji. All rights reserved.
//

#import "AddCoverView.h"
#import "ImageRightButton.h"
#import "AddButton.h"
#import "MBProgressHUD+MJ.h"

@interface AddCoverView()

@property (weak, nonatomic) IBOutlet AddButton *shareBtn;
@property (weak, nonatomic) IBOutlet AddButton *scanBtn;
@property (weak, nonatomic) IBOutlet AddButton *nearBtn;
@property (weak, nonatomic) IBOutlet UIButton *closeBtn;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *shareBottomCons;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *scanBottomCons;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *nearBottomCons;

@end

@implementation AddCoverView
- (void)awakeFromNib
{
    [super awakeFromNib];
}
+ (instancetype)addCoverView
{
    return [[[NSBundle mainBundle]loadNibNamed:NSStringFromClass([AddCoverView class]) owner:nil options:nil]lastObject];
}
- (void)showAnimation
{
    [UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:3.0 options:UIViewAnimationOptionLayoutSubviews animations:^{
        self.shareBtn.transform = CGAffineTransformMakeTranslation(0, -290);
        self.closeBtn.transform = CGAffineTransformMakeRotation(M_PI*0.25);
    } completion:nil];
    [UIView animateWithDuration:0.5 delay:0.1 usingSpringWithDamping:0.5 initialSpringVelocity:3.0 options:UIViewAnimationOptionLayoutSubviews animations:^{
        self.scanBtn.transform = CGAffineTransformMakeTranslation(0, -290);
    } completion:nil];
    [UIView animateWithDuration:0.5 delay:0.2 usingSpringWithDamping:0.5 initialSpringVelocity:3.0 options:UIViewAnimationOptionLayoutSubviews animations:^{
        self.nearBtn.transform = CGAffineTransformMakeTranslation(0, -290);
    } completion:nil];
}
- (void)dismissAnimation
{
    [UIView animateWithDuration:0.4 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:3.0 options:UIViewAnimationOptionLayoutSubviews animations:^{
        self.shareBtn.transform = CGAffineTransformIdentity;
        self.closeBtn.transform = CGAffineTransformIdentity;
    } completion:nil];
    [UIView animateWithDuration:0.4 delay:0.1 usingSpringWithDamping:0.5 initialSpringVelocity:3.0 options:UIViewAnimationOptionLayoutSubviews animations:^{
        self.scanBtn.transform = CGAffineTransformIdentity;
    } completion:nil];
    [UIView animateWithDuration:0.4 delay:0.2 usingSpringWithDamping:0.5 initialSpringVelocity:3.0 options:UIViewAnimationOptionLayoutSubviews animations:^{
        self.nearBtn.transform = CGAffineTransformIdentity;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
- (IBAction)btnClick:(ImageRightButton *)btn
{
    [self dismissAnimation];
    if ([self.delegate respondsToSelector:@selector(AddCoverViewClick:)]) {
        [self.delegate AddCoverViewClick:btn.tag];
    }
}
- (IBAction)addClick:(UIButton *)btn
{
    [self dismissAnimation];
    if (btn.tag != 3) {
        if ([self.delegate respondsToSelector:@selector(AddCoverViewClick:)]) {
            [self.delegate AddCoverViewClick:btn.tag];
        }
    }
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
//    [self dismissAnimation];
}

@end
